

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>04车辆状态</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.css">
    <style>
        /* 自定义样式 */
        .time-grid {
            min-width: calc(100vw - 280px);
        }
        .task-block {
            position: absolute;
            height: 50px;
            top: 15px;
        }
        .segment-block {
            position: absolute;
            height: 48px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 13px;
            line-height: 1.8;
        }
        .blue-segment {
            background-color: #3B82F6;
            color: white;
        }
        .preparation-segment {
            background-color: #98A2E7;
        }
        .grid-cell {
            min-width: 64px;
        }
        @media (max-width: 768px) {
            .time-grid {
                min-width: 800px;
            }
        }
        
        /* 导航栏样式 */
        .nav-item {
            position: relative;
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            overflow: hidden;
        }
        
        .nav-item:hover {
            background: linear-gradient(180deg, rgba(59, 130, 246, 0.05) 0%, rgba(30, 64, 175, 0.05) 100%);
            transform: translateY(-1px);
        }
        
        .nav-item:hover i {
            transform: scale(1.1);
        }
        
        .nav-item.active {
            color: #3B82F6;
            font-weight: 600;
        }
        
        .nav-item.active::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 50%;
            width: 80%;
            height: 3px;
            background: linear-gradient(90deg, #3B82F6, #1E40AF);
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            transform: translateX(-50%);
        }
        
        .nav-item i {
            transition: all 0.3s ease;
        }
        
        /* 页面标题样式 */
        .page-header {
            background: white;
            border-radius: 8px;
            padding: 20px;
            margin-bottom: 16px;
            border: 1px solid #e5e7eb;
        }
        
        .page-title {
            font-size: 1.5rem;
            font-weight: 600;
            color: #1f2937;
            margin-bottom: 4px;
        }
        
        .page-subtitle {
            color: #6b7280;
            font-size: 0.875rem;
        }
        
        .btn {
            padding: 8px 16px;
            border-radius: 6px;
            font-size: 0.875rem;
            font-weight: 500;
            transition: all 0.15s;
            cursor: pointer;
            border: 1px solid transparent;
        }
        
        .btn-primary {
            background-color: #3B82F6;
            color: white;
            border-color: #3B82F6;
        }
        
        .btn-primary:hover {
            background-color: #2563EB;
            border-color: #2563EB;
        }
        
        .btn-outline-primary {
            background-color: transparent;
            color: #3B82F6;
            border-color: #3B82F6;
        }
        
        .btn-outline-primary:hover {
            background-color: #3B82F6;
            color: white;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- 顶部标题栏 -->
    <header style="background: linear-gradient(135deg, #3B82F6 0%, #1E40AF 100%);" class="text-white py-2.5 px-6 shadow-xl">
        <div class="flex justify-between items-center">
            <div class="flex-1"></div>
            <h1 class="text-3xl font-bold flex-1 text-center tracking-wide">马鞍山非急救转运调度中心</h1>
            <div class="flex-1 flex justify-end items-center space-x-4">
                <div style="background: rgba(255, 255, 255, 0.2);" class="flex items-center space-x-3 px-4 py-2 rounded-full backdrop-blur-sm">
                    <i class="fas fa-user-circle text-xl"></i>
                    <span class="font-medium">调度员 张晓丽</span>
                </div>
                <button style="transition: all 0.3s ease;" class="text-white hover:bg-white/20 p-3 rounded-full transition-all duration-300 hover:rotate-90">
                    <i class="fas fa-cog text-xl"></i>
                </button>
            </div>
        </div>
    </header>

    <!-- 导航栏 -->
    <nav style="background: rgba(255, 255, 255, 0.95); backdrop-filter: blur(10px); border: 1px solid rgba(255, 255, 255, 0.2);" class="shadow-lg sticky top-0 z-50">
        <div class="flex justify-center">
            <a href="#" class="nav-item px-8 py-4 text-gray-700 flex items-center space-x-3">
                <i class="fas fa-th-large text-lg"></i>
                <span>调度中心</span>
            </a>
            <a href="#" class="nav-item px-8 py-4 text-gray-700 flex items-center space-x-3">
                <i class="fas fa-clipboard-list text-lg"></i>
                <span>订单管理</span>
            </a>
            <a href="#" class="nav-item px-8 py-4 text-gray-700 flex items-center space-x-3">
                <i class="fas fa-users text-lg"></i>
                <span>人员管理</span>
            </a>
            <a href="#" class="nav-item px-8 py-4 text-gray-700 flex items-center space-x-3">
                <i class="fas fa-ambulance text-lg"></i>
                <span>车辆管理</span>
            </a>
            <a href="#" class="nav-item active px-8 py-4 text-gray-700 flex items-center space-x-3">
                <i class="fas fa-truck text-lg"></i>
                <span>车辆状态</span>
            </a>
            <a href="#" class="nav-item px-8 py-4 text-gray-700 flex items-center space-x-3">
                <i class="fas fa-map-marked-alt text-lg"></i>
                <span>实时监控</span>
            </a>
            <a href="#" class="nav-item px-8 py-4 text-gray-700 flex items-center space-x-3">
                <i class="fas fa-coins text-lg"></i>
                <span>财务管理</span>
            </a>
        </div>
    </nav>

    <div class="main-container px-6 py-4">
        <!-- 页面标题 -->
        <div class="page-header">
            <div class="row align-items-center">
                <div class="col-md-6">
                    <h1 class="page-title">车辆状态</h1>
                    <p class="page-subtitle">查看和管理所有车辆的实时状态</p>
                </div>
                <div class="col-md-6 text-md-end mt-3 mt-md-0">
                    <button class="btn btn-primary me-2">
                        <i class="bi bi-download me-2"></i>导出报表
                    </button>
                    <button class="btn btn-outline-primary">
                        <i class="bi bi-printer me-2"></i>打印列表
                    </button>
                </div>
            </div>
        </div>
        
        <!-- 日期控制器和图例 -->
        <div class="flex justify-between items-center mb-4">
            <div class="flex items-center space-x-4">
                <button id="prevDate" class="p-2 hover:bg-gray-100 rounded cursor-pointer whitespace-nowrap">
                    <i class="fas fa-chevron-left text-gray-600"></i>
                </button>
                <span id="currentDate" class="text-lg font-medium">12月26日</span>
                <button id="nextDate" class="p-2 hover:bg-gray-100 rounded cursor-pointer whitespace-nowrap">
                    <i class="fas fa-chevron-right text-gray-600"></i>
                </button>
            </div>
            <div class="flex items-center space-x-6">
                <div class="flex items-center space-x-2">
                    <div class="w-4 h-4 bg-gray-300 rounded"></div>
                    <span class="text-sm text-gray-600">已完成任务</span>
                </div>
                <div class="flex items-center space-x-2">
                    <div class="w-4 h-4 bg-blue-500 rounded"></div>
                    <span class="text-sm text-gray-600">进行中任务</span>
                </div>
                <div class="flex items-center space-x-2">
                    <div class="w-4 h-4 bg-purple-500 rounded"></div>
                    <span class="text-sm text-gray-600">已预约任务</span>
                </div>
                <div class="flex items-center space-x-2">
                    <div class="w-4 h-4 rounded" style="background-color: #98A2E7;"></div>
                    <span class="text-sm text-gray-600">准备时段/返程时段</span>
                </div>
                <div class="flex items-center space-x-2">
                    <div class="w-4 h-4 bg-red-500 rounded"></div>
                    <span class="text-sm text-gray-600">已取消任务</span>
                </div>
            </div>
        </div>
        
        <!-- 调度表 -->
        <div class="bg-white rounded-lg shadow-sm border border-gray-200 overflow-hidden">
            <div class="flex">
                <!-- 车辆列表 -->
                <div class="w-64 bg-gradient-to-b from-gray-50 to-gray-100 border-r border-gray-200">
                    <div class="h-20 flex items-center justify-center bg-gradient-to-r from-gray-100 to-gray-200 border-b border-gray-200">
                        <span class="text-base font-semibold text-gray-700">车辆编号</span>
                    </div>
                    <div id="vehicleList"></div>
                </div>
                
                <!-- 时间网格 -->
                <div class="flex-1 overflow-x-auto min-w-0">
                    <!-- 时间轴头部 -->
                    <div id="timeHeader" class="flex bg-gradient-to-r from-gray-100 to-gray-200 border-b border-gray-300 time-grid"></div>
                    
                    <!-- 网格内容 -->
                    <div class="relative time-grid">
                        <div id="gridContent"></div>
                        <div id="taskBlocks"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        // 数据
        const vehicles = [
            { id: '皖E2K920', status: 'busy' },
            { id: '皖E7M318', status: 'busy' },
            { id: '皖E2L647', status: 'busy' },
            { id: '皖E5P632', status: 'busy' },
            { id: '皖E1H659', status: 'busy' },
            { id: '皖E4U924', status: 'free' },
            { id: '皖E5L681', status: 'free' },
            { id: '皖E6G943', status: 'free' },
            { id: '皖E4T516', status: 'free' },
            { id: '皖E6U792', status: 'free' }
        ];
        
        const timeSlots = [
            '06:00', '07:00', '08:00', '09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00',
            '16:00', '17:00', '18:00', '19:00', '20:00', '21:00', '22:00', '23:00', '00:00', '01:00',
            '02:00', '03:00', '04:00', '05:00', '06:00', '07:00'
        ];
        
        const tasksByDate = {
            '12月26日': [
                { vehicleIndex: 0, startCol: 1, endCol: 3, type: 'gray', text: '已完成任务' },
                { vehicleIndex: 0, startCol: 9, endCol: 12, type: 'combined', segments: [
                    { start: 0, end: 0.33, type: 'preparation', text: '' },
                    { start: 0.33, end: 2, type: 'blue', text: '起：江苏省苏州市\n终：浙江省杭州市' },
                    { start: 2, end: 3, type: 'preparation', text: '' }
                ]},
                { vehicleIndex: 1, startCol: 2, endCol: 4, type: 'gray', text: '已完成任务' },
                { vehicleIndex: 1, startCol: 6, endCol: 8, type: 'red', text: '已取消任务' },
                { vehicleIndex: 1, startCol: 8, endCol: 11, type: 'combined', segments: [
                    { start: 0, end: 0.33, type: 'preparation', text: '' },
                    { start: 0.33, end: 2, type: 'blue', text: '起：上海市浦东区\n终：江苏省无锡市' },
                    { start: 2, end: 3, type: 'preparation', text: '' }
                ]},
                { vehicleIndex: 1, startCol: 15, endCol: 17, type: 'purple', text: '起：浙江省宁波市\n终：江苏省南通市' },
                { vehicleIndex: 2, startCol: 1, endCol: 3, type: 'gray', text: '已完成任务' },
                { vehicleIndex: 2, startCol: 10, endCol: 13, type: 'combined', segments: [
                    { start: 0, end: 0.33, type: 'preparation', text: '' },
                    { start: 0.33, end: 2, type: 'blue', text: '起：安徽省合肥市\n终：山东省济南市' },
                    { start: 2, end: 3, type: 'preparation', text: '' }
                ]},
                { vehicleIndex: 3, startCol: 3, endCol: 5, type: 'gray', text: '已完成任务' },
                { vehicleIndex: 3, startCol: 11, endCol: 14, type: 'combined', segments: [
                    { start: 0, end: 0.33, type: 'preparation', text: '' },
                    { start: 0.33, end: 2, type: 'blue', text: '起：河南省郑州市\n终：湖北省武汉市' },
                    { start: 2, end: 3, type: 'preparation', text: '' }
                ]},
                { vehicleIndex: 4, startCol: 1, endCol: 3, type: 'gray', text: '已完成任务' },
                { vehicleIndex: 4, startCol: 9, endCol: 12, type: 'combined', segments: [
                    { start: 0, end: 0.33, type: 'preparation', text: '' },
                    { start: 0.33, end: 2, type: 'blue', text: '起：江西省南昌市\n终：福建省福州市' },
                    { start: 2, end: 3, type: 'preparation', text: '' }
                ]},
                { vehicleIndex: 4, startCol: 16, endCol: 18, type: 'purple', text: '起：广东省广州市\n终：广西省南宁市' },
                { vehicleIndex: 5, startCol: 2, endCol: 4, type: 'gray', text: '已完成任务' },
                { vehicleIndex: 5, startCol: 7, endCol: 9, type: 'red', text: '已取消任务' }
            ],
            '12月25日': [
                { vehicleIndex: 0, startCol: 2, endCol: 4, type: 'gray', text: '已完成任务' },
                { vehicleIndex: 0, startCol: 10, endCol: 13, type: 'gray', text: '已完成任务' },
                { vehicleIndex: 1, startCol: 1, endCol: 3, type: 'gray', text: '已完成任务' },
                { vehicleIndex: 1, startCol: 7, endCol: 10, type: 'red', text: '已取消任务' },
                { vehicleIndex: 2, startCol: 3, endCol: 5, type: 'gray', text: '已完成任务' },
                { vehicleIndex: 2, startCol: 12, endCol: 15, type: 'gray', text: '已完成任务' },
                { vehicleIndex: 3, startCol: 4, endCol: 6, type: 'gray', text: '已完成任务' },
                { vehicleIndex: 3, startCol: 14, endCol: 16, type: 'red', text: '已取消任务' },
                { vehicleIndex: 4, startCol: 2, endCol: 4, type: 'gray', text: '已完成任务' },
                { vehicleIndex: 5, startCol: 8, endCol: 11, type: 'gray', text: '已完成任务' }
            ],
            '12月27日': [
                { vehicleIndex: 0, startCol: 3, endCol: 5, type: 'gray', text: '已完成任务' },
                { vehicleIndex: 0, startCol: 11, endCol: 14, type: 'combined', segments: [
                    { start: 0, end: 0.33, type: 'preparation', text: '' },
                    { start: 0.33, end: 2, type: 'blue', text: '起：陕西省西安市\n终：甘肃省兰州市' },
                    { start: 2, end: 3, type: 'preparation', text: '' }
                ]},
                { vehicleIndex: 1, startCol: 4, endCol: 6, type: 'gray', text: '已完成任务' },
                { vehicleIndex: 1, startCol: 9, endCol: 12, type: 'combined', segments: [
                    { start: 0, end: 0.33, type: 'preparation', text: '' },
                    { start: 0.33, end: 2, type: 'blue', text: '起：新疆乌鲁木齐市\n终：青海省西宁市' },
                    { start: 2, end: 3, type: 'preparation', text: '' }
                ]},
                { vehicleIndex: 1, startCol: 17, endCol: 19, type: 'purple', text: '起：宁夏银川市\n终：内蒙古呼和浩特市' },
                { vehicleIndex: 2, startCol: 2, endCol: 4, type: 'gray', text: '已完成任务' },
                { vehicleIndex: 2, startCol: 13, endCol: 16, type: 'combined', segments: [
                    { start: 0, end: 0.33, type: 'preparation', text: '' },
                    { start: 0.33, end: 2, type: 'blue', text: '起：黑龙江省哈尔滨市\n终：吉林省长春市' },
                    { start: 2, end: 3, type: 'preparation', text: '' }
                ]},
                { vehicleIndex: 3, startCol: 1, endCol: 3, type: 'gray', text: '已完成任务' },
                { vehicleIndex: 4, startCol: 6, endCol: 8, type: 'gray', text: '已完成任务' },
                { vehicleIndex: 4, startCol: 15, endCol: 17, type: 'purple', text: '起：辽宁省沈阳市\n终：天津市' },
                { vehicleIndex: 5, startCol: 5, endCol: 7, type: 'gray', text: '已完成任务' }
            ]
        };
        
        // 状态
        let currentDate = '12月26日';
        
        // DOM 元素
        const currentDateEl = document.getElementById('currentDate');
        const prevDateBtn = document.getElementById('prevDate');
        const nextDateBtn = document.getElementById('nextDate');
        const vehicleListEl = document.getElementById('vehicleList');
        const timeHeaderEl = document.getElementById('timeHeader');
        const gridContentEl = document.getElementById('gridContent');
        const taskBlocksEl = document.getElementById('taskBlocks');
        
        // 初始化函数
        function init() {
            renderVehicleList();
            renderTimeHeader();
            renderGridContent();
            renderTasks();
        }
        
        // 渲染车辆列表
        function renderVehicleList() {
            vehicleListEl.innerHTML = '';
            vehicles.forEach((vehicle, index) => {
                const vehicleEl = document.createElement('div');
                vehicleEl.className = 'h-20 flex items-center justify-between px-6 border-b border-gray-200 hover:bg-gray-50 transition-colors';
                
                const statusClass = vehicle.status === 'busy' 
                    ? 'bg-red-100 text-red-700 border border-red-200' 
                    : 'bg-green-100 text-green-700 border border-green-200';
                const statusText = vehicle.status === 'busy' ? '忙碌' : '空闲';
                
                // 根据状态选择不同的图标
                const statusIcon = vehicle.status === 'busy' 
                    ? '<i class="fas fa-clock text-red-600 mr-1"></i>' 
                    : '<i class="fas fa-check-circle text-green-600 mr-1"></i>';
                
                vehicleEl.innerHTML = `
                    <div class="flex items-center space-x-3">
                        <i class="fas fa-ambulance text-blue-600 text-xl"></i>
                        <span class="text-base font-bold text-gray-800">${vehicle.id}</span>
                    </div>
                    <span class="px-3 py-1.5 text-sm rounded-full font-medium flex items-center ${statusClass}">
                        ${statusIcon}
                        ${statusText}
                    </span>
                `;
                
                vehicleListEl.appendChild(vehicleEl);
            });
        }
        
        // 渲染时间轴头部
        function renderTimeHeader() {
            timeHeaderEl.innerHTML = '';
            timeSlots.forEach((time, index) => {
                const timeEl = document.createElement('div');
                timeEl.className = 'flex-1 min-w-16 h-20 flex items-center justify-center border-r border-gray-300 text-sm font-medium text-gray-700 grid-cell';
                timeEl.textContent = time;
                timeHeaderEl.appendChild(timeEl);
            });
        }
        
        // 渲染网格内容
        function renderGridContent() {
            gridContentEl.innerHTML = '';
            vehicles.forEach((vehicle, vehicleIndex) => {
                const rowEl = document.createElement('div');
                rowEl.className = 'flex border-b border-gray-200 h-20';
                
                timeSlots.forEach((time, timeIndex) => {
                    const cellEl = document.createElement('div');
                    cellEl.className = 'flex-1 min-w-16 h-20 border-r border-gray-200 bg-white hover:bg-gray-50 transition-colors grid-cell';
                    rowEl.appendChild(cellEl);
                });
                
                gridContentEl.appendChild(rowEl);
            });
        }
        
        // 渲染任务
        function renderTasks() {
            taskBlocksEl.innerHTML = '';
            const tasks = tasksByDate[currentDate] || [];
            
            tasks.forEach((task, taskIndex) => {
                if (task.type === 'combined') {
                    const taskEl = document.createElement('div');
                    taskEl.className = 'task-block';
                    taskEl.style.top = `${task.vehicleIndex * 80 + 15}px`;
                    taskEl.style.left = `calc(${task.startCol} * (100vw - 280px) / ${timeSlots.length})`;
                    taskEl.style.width = `calc(${task.endCol - task.startCol} * (100vw - 280px) / ${timeSlots.length} - 8px)`;
                    
                    task.segments.forEach((segment, segmentIndex) => {
                        const segmentEl = document.createElement('div');
                        segmentEl.className = 'segment-block';
                        
                        if (segment.type === 'blue') {
                            segmentEl.classList.add('blue-segment');
                        } else if (segment.type === 'preparation') {
                            segmentEl.classList.add('preparation-segment');
                        }
                        
                        segmentEl.style.left = `${segment.start * 100 / 3}%`;
                        segmentEl.style.width = `${(segment.end - segment.start) * 100 / 3}%`;
                        
                        if (segmentIndex === 0) {
                            segmentEl.style.borderRadius = '6px 0 0 6px';
                        } else if (segmentIndex === task.segments.length - 1) {
                            segmentEl.style.borderRadius = '0 6px 6px 0';
                        }
                        
                        if (segment.type === 'blue') {
                            segmentEl.innerHTML = `<span class="truncate text-center px-1" style="white-space: pre-line">${segment.text}</span>`;
                        }
                        
                        taskEl.appendChild(segmentEl);
                    });
                    
                    taskBlocksEl.appendChild(taskEl);
                } else {
                    const taskEl = document.createElement('div');
                    taskEl.className = 'absolute h-12 rounded-md px-3 flex items-center text-sm font-medium shadow-sm transition-colors cursor-pointer';
                    
                    if (task.type === 'blue') {
                        taskEl.classList.add('bg-blue-500', 'text-white', 'hover:bg-blue-600');
                    } else if (task.type === 'purple') {
                        taskEl.classList.add('bg-purple-500', 'text-white', 'hover:bg-purple-600');
                    } else if (task.type === 'gray') {
                        taskEl.classList.add('bg-gray-400', 'text-white', 'hover:bg-gray-500');
                    } else if (task.type === 'red') {
                        taskEl.classList.add('bg-red-500', 'text-white', 'hover:bg-red-600');
                    }
                    
                    taskEl.style.top = `${task.vehicleIndex * 80 + 15}px`;
                    taskEl.style.left = `calc(${task.startCol} * (100vw - 280px) / ${timeSlots.length})`;
                    taskEl.style.width = `calc(${task.endCol - task.startCol} * (100vw - 280px) / ${timeSlots.length} - 8px)`;
                    
                    taskEl.innerHTML = `<span class="truncate text-center" style="font-size: 13px; line-height: 1.8; white-space: pre-line">${task.text}</span>`;
                    
                    taskBlocksEl.appendChild(taskEl);
                }
            });
        }
        
        // 日期处理函数
        function handleDateChange(direction) {
            const currentDay = parseInt(currentDate.replace('12月', '').replace('日', ''));
            let newDay;
            
            if (direction === 'prev') {
                newDay = currentDay - 1;
                if (newDay < 1) {
                    newDay = 31; // 假设是12月，最多31天
                }
            } else {
                newDay = currentDay + 1;
                if (newDay > 31) {
                    newDay = 1;
                }
            }
            
            currentDate = `12月${newDay}日`;
            currentDateEl.textContent = currentDate;
            renderTasks();
        }
        
        // 事件监听
        prevDateBtn.addEventListener('click', () => handleDateChange('prev'));
        nextDateBtn.addEventListener('click', () => handleDateChange('next'));
        
        // 导航栏切换
        document.querySelectorAll('.nav-item').forEach(item => {
            item.addEventListener('click', function(e) {
                e.preventDefault();
                
                // 移除所有活动状态
                document.querySelectorAll('.nav-item').forEach(nav => {
                    nav.classList.remove('active');
                });
                
                // 添加活动状态到当前项
                this.classList.add('active');
            });
        });
        
        // 初始化
        init();
    </script>
</body>
</html>